package cn.wangqi.personal.dao;

import cn.wangqi.personal.domain.Collage;
import cn.wangqi.personal.util.Page;
import org.apache.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 *created by admin  2017-09-07 11:23:01
 */
@Repository
public class CollageDao{
    private final String NAMESPACE = this.getClass().getName() + ".";
    private Logger logger = Logger.getLogger(CollageDao.class);
    @Resource
    protected SqlSessionTemplate mainSqlSession;
    public void saveCollage(Collage collage) {
        mainSqlSession.insert(NAMESPACE + "saveCollage", collage);
    }

    public void saveCollage(List<Collage> collage) {
        mainSqlSession.insert(NAMESPACE + "saveCollageList", collage);
    }

    public void deleteCollageById(int collageId) {
        mainSqlSession.delete(NAMESPACE + "deleteCollageById", collageId);
    }

    public Collage findCollageById(int collageId){
        return mainSqlSession.selectOne(NAMESPACE + "findCollageById", collageId);
    }

    public List<Collage> listCollage(Page page){
        Map<String, Object> params = new HashMap<>();
        params.put("page",page);
        return mainSqlSession.selectList(NAMESPACE + "listCollage", params);
    }

    public int countCollage(){
        Map<String, Object> params = new HashMap<>();
        return mainSqlSession.selectOne(NAMESPACE + "countCollage",params);
    }

    public void updateCollage(Collage collage){
        mainSqlSession.update(NAMESPACE + "updateCollage", collage);
    }

}
